package com.sf.service.impl;

import com.sf.domain.Department;
import com.sf.ex.BusinessException;
import com.sf.mapper.DepartmentMapper;
import com.sf.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public List<Department> list() {

        return departmentMapper.list();
    }

    @Override
    public void delete(Long id) {
        // 如果id 等于null, 抛出异常, 告诉前端id 不能为空
        if(id == null){
            throw new BusinessException("id 不能为空");
        }
        departmentMapper.delete(id);
    }

    @Override
    public void save(Department department) {
        departmentMapper.insert(department);
    }

    @Override
    public void update(Department department) {
        departmentMapper.update(department);
    }

    @Override
    public Department get(Long id) {
       return departmentMapper.get(id);
    }
}
